package com.bibrApp.difu.actvity.notice_detail_mvp;

import android.content.Context;

import com.bibrApp.difu.api.RetrofitNet;
import com.bibrApp.difu.base.BasePresenter;
import com.google.gson.Gson;

import java.util.LinkedHashMap;
import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.RequestBody;

public class NoticeDetailPresenter extends BasePresenter<INoticeDetailView> {
    NoticeDetailPresenter(Context context, INoticeDetailView iView) {
        super(context, iView);
    }

    public void getNoticeDetail(String id) {
        Map<String, Object> params = new LinkedHashMap<>();
        params.put("id", id);
        RetrofitNet.getInstance().getApi()
                .getNoticeDetail(RequestBody.create(MediaType.parse("application/json"), new Gson().toJson(params)))
                .compose(getActivityLifecycleProvider().bindToLifecycle())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(o -> iView.successOfNotice(o), throwable -> {
                    iView.error("服务器异常");
                });
    }
}
